ShowTable of Contents
Overview
Various features add contributions to the launcher (Open) menu.
These additions may be added declaratively via the launcher extension point or programmatically. A common request is to remove specific items to suit customization. How might one remove such items?
LauncherManager
The LauncherManager within the com.ibm.rcp.ui plugin provides the mechanism to programmatically add and remove items from the launcher. The following code demonstrates how the Composite Applications launch item may be removed.
if(PlatformUI.isWorkbenchRunning()){
LauncherManager lm = LauncherManager.getInstance();
// removes the "Composite Applications" launch contribution
IContributionItem item = lm.find("com.ibm.rcp.portal.catalog.ui.perspectives.CatalogPerspective.Catalog");
if(item != null){
lm.remove(item);
lm.update(true);
}
}
Rather than list all the IDs of contributed items, it is useful to iterate over the current contributions to determine the item's ID. Once the ID is known, it may be used to find() and remove() as shown above.
if(PlatformUI.isWorkbenchRunning()){
LauncherManager lm = LauncherManager.getInstance();
for(IContributionItem item : lm.getItems()){
System.out.println(item);
}
}
This code produces many results, one of which is the Synchronization item:
com.ibm.rcp.ui.launcher.PerspectiveLauncherContributionItem(id=com.ibm.rcp.syncui.launcherItem)
(Label=Synchronization)
(PluginId=com.ibm.rcp.ui)
(has normal image descriptor=FileImageDescriptor(location=class com.ibm.rcp.syncui.SyncUIStartup, name=resources/Synchronization_16x16.png))
(path=additions)
(AutoStart=false)
Special Cases
The Composite Applications item is a special case since it may be re-added by other operation even after initial removal. To counteract this designed behavior, a listener can be used to listen for additions and call the previously used code to again remove the item.
// prevent it from being re-added by other XPD operations
Job.getJobManager().addJobChangeListener(new IJobChangeListener(){
@Override
public void aboutToRun(IJobChangeEvent event) {
}
@Override
public void awake(IJobChangeEvent event) {
}
@Override
public void done(IJobChangeEvent event) {
Job job = event.getJob();
if(job.getName().equals("Update catalog launcher entry")){
removeCatalogLaunchItem();
}
}
@Override
public void running(IJobChangeEvent event) {
}
@Override
public void scheduled(IJobChangeEvent event) {
}
@Override
public void sleeping(IJobChangeEvent event) {
}
});